<template>
    <div>
        <h3>修改</h3>
        <table class="table">
            <tbody>
                <tr>
                    <td>会员名称</td>
                    <td>
                        <input type="text" v-model="data.hymc"> 
                    </td>
                </tr>
                <tr>
                    <td>会员等级</td>
                    <td>
                        <select v-model="data.hydj">
                            <option value="">请选择</option>
                            <option value="黄金">黄金</option>
                            <option value="白银">白银</option>
                            <option value="青铜">青铜</option>
                            <option value="王者">王者</option>
                            <option value="高级">高级</option>
                            <option value="低级">低级</option>
                            <option value="中级">中级</option>
                        </select>
                       
                    </td>
                </tr>
                <tr>
                    <td>会员性别</td>
                    <td>
                        <input type="radio"  name="5" value="男" v-model="data.hyxb">男
                        <input type="radio"  name="5" value="女" v-model="data.hyxb">女
                    </td>
                </tr>
                <tr>
                    <td>上传头像</td>
                    <td>
                        <input type="file" @change="tpsw">
                        <img :src="'https://localhost:7267/'+data.hydz" style="width: 60px;height: 60px;">
                    </td>
                </tr>
                <tr>
                    <td>年龄</td>
                    <td>
                        <input type="text"v-model="data.nl">
                    </td>
                </tr>
                <tr>
                    <td>会员状态</td>
                    <td>
                        <input type="checkbox" value="true" v-model="data.hyzt">选中表是启用未选中表示禁用
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" @click="xg">
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRoute } from 'vue-router';


const str = useRoute();
const data=ref({
    "hyid": 0,
  "hymc": "string",
  "hydj": "",
  "hyxb": "string",
  "hydz": "string",
  "nl": 0,
  "hyzt": true
})
onMounted(()=>{
 xss();
})
const xss=()=>{
    debugger
  var st = str.query.hyid
    axios.get("https://localhost:7267/api/hy/hyxss",{params:{hyid:st}}).then(res=>{
        data.value=res.data
    })
 }


const tpsw=(a:any)=>{
    var  f = a.target.files[0];
    var fs = new FormData;
    debugger
    fs.append("file",f);
    if(f.size>=1024*1024*2){
        alert("图片上传大小不得超过2MB")
        return
    }
    if(f.type!="image/jpeg"&&f.type!="image/png"){
        alert("图片类型不是(jpg、png)")
        return
    }
    axios.post("https://localhost:7267/api/tp/tps",fs).then(res=>{
        data.value.hydz = res.data 
   })
}



 const xg=()=>{
    axios.post("https://localhost:7267/api/hy/hyupdate",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功");
            location.href ="/hyxs"
        }else{
            alert("修改失败")
        }
    })
 }

</script>

<style scoped>

</style>